//
//  OptionViewController.m
//  礼物go
//
//  Created by dllo on 16/6/1.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "OptionViewController.h"
#import "OptionTableViewCell.h"
#import <MBProgressHUD.h>


@interface OptionViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *optionTableView;


@end

@implementation OptionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"设置";
    self.navigationController.navigationBar.translucent = NO;
 self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    
    self.optionTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.optionTableView.dk_backgroundColorPicker = DKColorPickerWithRGB(0xFFFAFA,0xBEBEBE);
    
    self.optionTableView.dataSource = self;
    self.optionTableView.delegate = self;
    [self.view addSubview:self.optionTableView];
    [self.optionTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"optionCell"];
    self.optionTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    // Do any additional setup after loading the view.
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"optionCell"];
    if (indexPath.row == 0) {
        cell.textLabel.text = @"清除缓存";
        cell.imageView.image = [UIImage imageNamed:@"iconClear_26x26_@2x"];
    } else {
        cell.textLabel.text = @"夜间模式";
        cell.imageView.image = [UIImage imageNamed:@"iconNightmodeSetting_26x26_@2x"];
        UISwitch *nightSwitch = [[UISwitch alloc] init];
        cell.accessoryView = nightSwitch;
         NSLog(@"%@",self.dk_manager.themeVersion);
        if (self.dk_manager.themeVersion == DKThemeVersionNight) {
            nightSwitch.on = YES;
        }
        
        nightSwitch.onTintColor = [UIColor grayColor];
        [nightSwitch addTarget:self action:@selector(handleNight:) forControlEvents:UIControlEventValueChanged];
    }
    
cell.dk_backgroundColorPicker = DKColorPickerWithRGB(0xFFFAFA,0xBEBEBE);
    
    return cell;

}

-(void)handleNight:(UISwitch *)night{
    
    if ([self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) {
       // NSLog(@"白天");
        [self.dk_manager dawnComing];
       
    } else {
       // NSLog(@"晚上");
     [self.dk_manager nightFalling];
       
    }



}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.mode = MBProgressHUDModeAnnularDeterminate;
       //获取缓存大小
        NSUInteger size = [[SDImageCache sharedImageCache] getSize];
        float cacheSize = size / 1024.0 / 1024.0;
        hud.labelText = [NSString stringWithFormat:@"正在清除%.1fM缓存",cacheSize];
        [hud showAnimated:YES whileExecutingBlock:^{
            [[SDImageCache sharedImageCache] clearDisk];
            
            float progress = 0.0f;
            while (progress < 1.0f)
            {
                progress += 0.02f;
                hud.progress = progress;
                usleep(50000);
            }
            
        } completionBlock:^{
            [hud removeFromSuperview];
           
        }];

    }


}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
